package com.controller;

import com.service.DeptService;
import org.springframework.context.ApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/dept")
public class DeptNameServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = 2;
        ApplicationContext context = SpringUtil.getSpringContext(req);
        DeptService deptService = context.getBean("deptService", DeptService.class);
        String name = deptService.getNameById(id);
        req.setAttribute("deptname", name);
        req.getRequestDispatcher("/WEB-INF/dept.jsp").forward(req, resp);
    }
}
